package cn.webrx.chat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class ScUtil {
    private Socket socket;
    private PrintWriter out;
    private BufferedReader read;

    public ScUtil() {

    }

    public ScUtil(Socket socket) {
        try {
            this.socket = socket;
            this.out = new PrintWriter(this.socket.getOutputStream());
            this.read = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public void send() {
        while (true) {
            out.write((new Scanner(System.in)).nextLine() + "\r\n");
            out.flush();
        }
    }

    public void read() {
        while (true) {
            try {
                String sss = this.read.readLine();
                System.out.println(sss);
            } catch (Exception e) {

            }finally {
                System.out.println("对方下线了");
                break;
            }
        }
    }
}
